#####################################
##        PEinjector/utils         ##
#####################################

import os


def find_disk() -> str:  # This code from dashedgeless
    disk_list = "CDEFGHIJKABLMNOPQRSTUVWYZ"
    for i in disk_list:
        this_disk = i + ":"
        if os.path.exists(this_disk + "/PEinjector"):
            return this_disk
    raise OSError(
        "Cannot find the PEinjector disk!")



class Version:
    def __init__(self, version: str):
        self.__version = [int(i) for i in version.split(".") if i.isdigit()]
        self.__version_str = version

    def __str__(self):
        return self.__version_str
    
    def __lt__(self, other):
        if not isinstance(other, Version) and not isinstance(other, str):
            raise TypeError(f"Cannot compare version with {type(other)}")
        if isinstance(other, str):
            other = Version(other)
        for i in range(min(len(self.__version), len(other.__version))):
            if self.__version[i] < other.__version[i]:
                return True
            elif self.__version[i] > other.__version[i]:
                return False
        if(len(self.__version) < len(other.__version)):
            return True
        return False
    
    def __eq__(self, other):
        if not isinstance(other, Version) and not isinstance(other, str):
            raise TypeError(f"Cannot compare version with {type(other)}")
        if isinstance(other, str):
            return self.__version_str == other
        return self.__version == other.__version

    def __ne__(self, other):
        return not self.__eq__(other)
    
    def __le__(self, other):
        return self.__lt__(other) or self.__eq__(other)
    
    def __ge__(self, other):
        return self.__gt__(other) or self.__eq__(other)
    
    def __gt__(self, other):
        return not self.__lt__(other) and not self.__eq__(other)